<?php
namespace Home\Controller;
use Lib\Alidayu\SendSMS;
class SignorderController extends CommonController {

public function _initialize()
{
		$this->Is_login();        //检测用户登录信息,如果错误直接返回错误,终止程序
		$this->Is_power("order");        //检测用户权限,如果错误直接返回错误,终止程序
		$this->assign('heardadminData',session('heardadminData'));
}
//新订单列表
public function signorder_list()
{
		// p($_POST);exit();
		$db_order = M("order o");
		$soundtype = I('get.soundtype');
		$order_name = I('get.order_name');
		$levelkey = I('get.levelkey');
		$mid = I('get.mid')?I('get.mid'):0;
		$this->p = I('get.p')?I('get.p'):1;
		$statustype = I('get.statustype')?I('get.statustype'):0;
		$this->soundtype = $soundtype;
		$this->order_name = $order_name;
		$this->levelkey = $levelkey;
		$this->statustype = $statustype;
		$where = "o.status!=0 and o.sub_type=0 and o.pay_status=1 and o.type=2 ";
		if (!empty($soundtype)) {$where .= " and category = \"".($soundtype)."\" ";}
		if (!empty($levelkey)) {$where .= " and `level` = \"".$levelkey."\" ";}
		if (!empty($order_name)) {$where .= " and (media_name like '%$order_name%' or o.id like '%$order_name%' or title like '%$order_name%' or article_id like '%$order_name%')";}
		if (!empty($mid)) {$where .= " and (media_id = $mid)";}
		if (!empty($statustype)) {$where .= " and (o.status=11 or o.status=12 or o.status=13 or o.status=15)";}
		// echo $where;exit();
		$count = $db_order->where($where)->join('__SYSTEMSETUP__ s ON o.level = s.id')->field('o.*,s.message level_type')->order('o.id desc')->count();
		$p = getpage($count, 20);
		$orderinfo = $db_order->where($where)->join('__BGM__ b on b.id = o.bgm_id','left')->join('__SYSTEMSETUP__ s ON o.level = s.id')->field('o.*,s.message level_type,b.audio')->order('id desc')->limit($p->firstRow, $p->listRows)->select();
		$leveldata = M("systemsetup")->where(array("type"=>1))->order('value desc')->select();
		$labeldata = M("label")->select();//读取配置
		//查询所签约单转单次数[oid=>count]
		$slip_list = M('signreorderlog')->group('oid')->getField('oid,count(id)',true);
		foreach ($orderinfo as $key => &$value) {
			$value['slip_count'] = $slip_list[$value['id']]?$slip_list[$value['id']]:0;
			if($value['slip_count'] > 0){//有转单
				$value['slip_last_time'] = M('signreorderlog')->where(['oid'=>$value['id']])->order('time DESC')->getField('time');
			}
			$value['usemoney'] = moneyzero($value['usemoney']*2);
			// $value['paytype'] = "字数";
			if ($value['status'] == 11||$value['status'] == 12 || $value['status'] == 1) {
				$order_lists = json_decode(RedisGet('order'.$value['id']),TRUE);
				$order_list = $order_lists['list'];
				foreach ($order_list as $key => $vo) {
					$value['user_id'] = $key;
				}
			}
		}
		$page = $p->show();
		// 获取查询参数
		$map['order_name'] = empty($order_name)?"":$order_name;
		$map['soundtype'] = $soundtype;
		$map['levelkey'] = $levelkey;
		$map['statustype'] = $statustype;
		$p->parameter = "";
		foreach($map as $key=>$val) {
				$p->parameter .= "$key=".urlencode($val)."&";
		}
		// p($p);exit();
		$this->assign('orderinfo',$orderinfo);
		$this->assign('labeldata',$labeldata);
		$this->assign('leveldata',$leveldata);
		$this->assign('page', $page);
		$this->display();
}
//创建订单
public function signorder_add()
{
		// $labeldata = M("label")->select();//读取配置
		$medialist = M("media")->field('id,media_name')->select();
		$leveldata = M("systemsetup")->where(array("type"=>1))->order('value desc')->select();
		$systemdata = M("systemsetup")->where(array("type"=>0))->select();
		// p($systemdata);exit();
		// $this->assign('labeldata',$labeldata);
		$this->assign('medialist',$medialist);
		$this->assign('leveldata',$leveldata);
		$this->assign('systemdata',$systemdata);
		$this->display();
}
public function media_ajax(){
	$media_id = I('get.media_id');
	$data['media'] = M("media")->field('mmid,uuid,timepoint')->where("id=$media_id")->find();
	$data['member'] = M("member")->field('level,sex,nickname')->where(array('uuid'=>$data['media']['uuid']))->find();
	if (!empty($data['member'])) {
		$leveldata = M("systemsetup")->where(array("type"=>1))->order('value asc')->select();
		foreach ($leveldata as $k => $v) {
			if($data['member']['level'] >= $v['value']){
				$data['member']['level_message'] = $v['message'];
				$data['member']['level_money'] = $v['money'];
				$data['member']['level_id'] = $v['id'];
			}
		}
	}
	$mmid = $data['media']['mmid'];
	$data['special'] = M("mediaspecial")->field('id,specialname')->where("mediaid=$mmid")->select();
	exit(json_encode($data));
}
public function add_signorder()
{
	// p($_POST);exit();
	$oid = I('post.oid');
	$mid = I('post.media');//自媒体id
	$special = I('post.special');//专辑id
	$demand = 0;//I('post.demand');//订单类型
	$soundtype = I('post.soundtype');//声音类型
	$sex = I('post.sex');//性别
	$speed = I('post.speed');//订单类型
	$title = I('post.title');//标题
	$article = I('post.article');//文章
	$level = I('post.level');//主播等级id
	$wordid = I('post.wordid');//字数
	$expectedtime = I('post.expectedtime');//预计时间（分钟）
	$moneyid = I('post.moneyid');//原价
	$usemoney = I('post.usemoney');//实价
	$mintime = I('post.mintime');//每千字用时（秒）
	$delayed = 0;//I('post.delayed');//加时（秒）
	$perprice = 0;//I('post.perprice');//变价%
	$media = M("media")->where(array("id"=>$mid))->field('media_name,timepoint')->find();
	$systemdata = M("systemsetup")->where("id=3")->where(array("type"=>0))->find();
	$wordstime = M("systemsetup")->where("id=22")->where(array("type"=>0))->find()['value'];
	$content = $this->PostOss($article);
	if (!$content) {
		$this->error('文章参数错误',"",1);
	}

	$mediatime = strtotime(date("Y-m-d",time())." ".$media['timepoint'].":0:0");
	if ($mediatime<time()) {
		$mediatime = strtotime(date("Y-m-d",time()+86400)." ".$media['timepoint'].":0:0");
	}
	$delayed = $mediatime-time();
	$order = D("order");
	if (!$order->create()){//自动验证
		$this->error('参数错误',"",1);
	}else{
		$now_time = time();
		// $data = $order->create(); // 保存生成的数据对象
		$data['mid'] = $mid;
		$data['mname'] = $media['media_name'];
		$data['soundtype'] = $soundtype;
		$data['speed'] = $speed;
		$data['createtime'] = $now_time;
		$data['expectedtime'] = $expectedtime*60;
		$data['largestid'] = 1;
		$data['circulationtime'] = $delayed;
		$data['title'] = $title;
		$data['words'] = $wordid;
		$data['content'] = $content;
		$data['id'] = get_orderid();
		$data['status'] = 1;
		$data['attribute'] = 1;
		$data['demand'] = $demand;
		$data['money'] = $moneyid;
		$data['premium'] = abs($usemoney-$moneyid);
		$data['sex'] = $sex;
		$data['special'] = $special;
		$data['level'] = $level;
		$wordnum = $wordnum<1000?1000:$wordnum;
		$data['wordstime'] = ceil($wordnum/1000)*$wordstime;
		$data['fail'] = 0;

		// p($data);exit();
		$result = $order->add($data);

		$db_order = M("order");

		// $data['is_pay'] = 1;
		// $data['pay_time'] = time();
		// $db_order->where(array('id'=>$result))->save($data);//更新数据
		// $this->signorder_push($result);
		// p($data);exit();

		$this->redirect('/Home/Signorder/edit_article', array('oid' => $result), 1, '页面跳转中...');
	}

}
public function edit_article(){
	$oid = I('get.oid');
	$articledata = M('order')->where("id = $oid")->find();
	$content = $this->GetOss($articledata['content']);
	$article = str_replace(array("(",")"),array("（","）"),$content);
	$leftarr = explode("（", $article);
	$num = 0;
	foreach ($leftarr as $key1 => &$value1) {
		if ($key1 != 0) {
			$str = "）&lt;/font&gt;&lt;a class=a".$key1." id=del".$key1." onclick='delTime(this)'&gt;&lt;img src='/Public/admin/sncss/images/delete.png'&gt;&lt;/a&gt;";
			$value1 = str_replace("）",$str,$value1);
			$value1 = "&lt;font color=#ff0001 class=a".$key1."&gt;（".$value1;
		}
		$num = $key1;
	}
	$articledata['article'] = implode("", $leftarr);
	$articledata['article'] = html_entity_decode($articledata['article']);
	// p($articledata);exit();
	$this->assign('articledata',$articledata);
	$this->assign('num',$num);
	$this->display();
}
public function next_signorder(){
	// p($_POST);exit();
	$oid = I('post.oid');
	$article = I('post.article');
	$content = $this->PostOss($article);

	$article = str_replace("#ff0001","",$article);
	// p($article);exit();
	$db_order = M("order");
	$db_order->where(array('id'=>$oid))->save(array("content"=>$content));//更新数据
	// $o = $db_order->field('id,mid,is_collect,id,level')->where("id = $oid")->find();
	$this->success('下单成功，请支付',"/Home/Signorder/signorder_list",1);
}
public function confirm_pay(){
	$oid = I('get.oid');
	$db_order = M("order");
	$data['is_pay'] = 1;
	$data['pay_time'] = time();
	$db_order->where(array('id'=>$oid))->save($data);//更新数据
	$this->signorder_push($oid);
	$this->success('支付成功，已通知主播接单',"/Home/Signorder/signorder_list",1);
}

/*给对应主播发消息
oid 				订单id
mid 				自媒体id
id 			订单编号
level 			级别id
type 				声音类型
*/
public function signorder_push($oid){
	$db_order = M("order");
	$db_media = M("media");
	$orderdata = $db_order->where(array("id"=>$oid))->find();
	$mid = $db_order->field('mid')->where(array("id"=>$oid))->find()['mid'];
	$signuser = $db_media->field('uuid')->where(array("id"=>$mid))->find()['uuid'];
	$systemdata = M("systemsetup")->where("id=25")->where(array("type"=>0))->find();
	$wechatinfo = M("wechat")->where("uuid=$signuser")->find();
	$array['oid'] = $oid;
	$array['uuid'] = $signuser;
	$array['receivingtime'] = time();
	$array['timelimit'] = $systemdata['value'];
	$array['sign'] = 1;
	$array['issign'] = 1;
	$res = M("orderinfo")->add($array);
	if ($res) {
		$systemdata = M("systemsetup")->where("id=4")->where(array("type"=>0))->find();
		// $GetSingAccessToken = $this->GetSingAccessToken();
		// $GetAccessToken = $this->GetAccessToken();
		$pusharray[] = $this->sendorderMessage($wechatinfo,$orderdata,$systemdata['value']);
		$res = curl_multi($pusharray);
	}
}

public function cancel_signorder(){
	$oid = I('get.oid');
	$db_signorder = M("signorder");
	$data['status'] = 7;
	$db_signorder->where(array('id'=>$oid))->save($data);//更新数据
	$this->success('重新下单跳转',"/Home/Signorder/signorder_add",1);
}
//订单详情
public function signorder_reorder()
{
		$oid = I('get.oid');
		$db_signorder = M("signorder");
		$labeldata = M("label")->select();//读取配置
		// $db_member = M("member");
		// $signorderdata = $db_member->where(array('status'=>9,'id'=>$uid))->find();
		$signorderdata = $db_signorder->where(array("id"=>$oid))->find();
		$articledata = M('article')->where(array("oid"=>$oid))->find();
		$medialist = M("media")->field('id,media_name')->select();
		$leveldata = M("systemsetup")->where(array("type"=>1))->order('value desc')->select();
		$signorderdata['ptime'] = round(($signorderdata['plantime']-$signorderdata['starttime'])/60);
		$special = $signorderdata['special'];
		$mid = $signorderdata['mid'];
		$mmid = M("media")->where(array("id"=>$mid))->field('mmid')->find()['mmid'];
		$specialdata = M("mediaspecial")->field('id,specialname')->where("mediaid=$mmid")->select();
		// p($specialdata);exit();
		$this->assign('signorderdata',$signorderdata);
		$this->assign('labeldata',$labeldata);
		$this->assign('medialist',$medialist);
		$this->assign('articledata',$articledata);
		$this->assign('leveldata',$leveldata);
		$this->assign('specialdata',$specialdata);
		$this->display();
}

function getwebcontent(){
	$url = $_POST['user_url'];
	$url = str_replace("https","http",$url);
	Vendor('phpQuery.phpQuery');

	$result = do_curl($url);
	$result = str_replace("<!--headTrap<body></body><head></head><html></html>-->", "", $result);
	\phpQuery::newDocumentHTML($result);
	if (strpos($url, "mp.weixin.qq.com") !== false) {
		$title = trim(pq('.rich_media_title')->html());
		$str = pq('#js_content')->html();
	// p($str);exit();
	}elseif (strpos($url, "shimo.im") !== false) {
		// echo "shimo";exit();
		$str =  htmlspecialchars(file_get_contents($url));
	// echo $str;exit();
		$str = preg_replace("/\s+/", " ", $str); //过滤多余回车
		$title = explode('content', strval($str))[0];
		$title = explode('title', strval($title))[1];
		$title = substr(substr($title,0,-5), 4);
		// p($title);exit();
		$str = explode('content', strval($str))[8];
		$str = explode('attribs', strval($str))[0];
		$str = substr(substr($str,0,-15), 41);
		// p($str);exit();
		$str = str_replace("*","",$str);
		$str = str_replace("\\\\n","<br />",$str);
		// p($str);exit();
	}elseif (strpos($url, "www.jianshu.com") !== false) {
		$title = trim(pq('.title')->html());
		$str = pq('.show-content')->html();
	}

	// $str =  htmlspecialchars($str);
	// echo $str;exit();
	$data['title'] = $title;
	$data['message'] = $str;
	exit(json_encode($data));
}

//阿里大于
	public function orderAlidayu($tel="13091718183",$Code='SMS_72800028',$name,$media,$time)
	{
		$alidayu = new SendSMS();
		$result = $alidayu->send($recNum=$tel,$smsParam='{"name":"'.$name.'","media":"'.$media.'","time":"'.$time.'"}',$smsTemplateCode=$Code,$smsFreesignName='听说Heard');
		// p($result);
	}
public function signreorder_push(){
	// p($_POST);exit();
	$jumpurl = $_SERVER["HTTP_REFERER"];
	$uuid = trim(I('post.uuid'));
	$oid = I('post.oid');
	$p = I('post.p');
	$res = M("member")->where(array("uuid"=>$uuid,"authentication"=>1))->find();
	if ($res) {
		$db_order = M("order");
		$orderdata = $db_order->where(array("id"=>$oid))->find();
		$systemdata = M("systemsetup")->where("id=25")->where(array("type"=>0))->find();
		$wechatinfo = M("wechat")->where("uuid=$uuid")->find();
		$now_time = time();
		$arr['add_time'] = date("YmdH",$now_time);
//		$arr['createtime'] = $now_time;
		$arr['pay_time'] = $now_time;
		$arr['actual_join_num'] = 0;
		$arr['status'] = 1;
		$arr['delay_time'] = 0;
		$arr['score'] = 0;
		$arr['audio_link'] = NULL;
		$arr['audio_upload_time'] = NULL;
		$arr['wav_link'] = NULL;
		$arr['wav_upload_time'] = NULL;
		$arr['delay_type'] = 1;
		$order_lists = json_decode(RedisGet('order'.$oid),TRUE);
		$order_list = $order_lists['list'];
		foreach ($order_list as $k => $vo) {
			$olduuid = $k;
		}
		// RedisDelete('order'.$oid);
		$olduuid_array = json_decode(RedisGet("uuid".$olduuid),TRUE);
		foreach ($olduuid_array['order_list'] as $key => $value) {
			if ($value['oid'] == $oid) {
				// p($value);echo $key;
				unset($olduuid_array['order_list'][$key]);
			}
		}
		RedisSet('uuid'.$olduuid,json_encode($olduuid_array));
		// exit();
		$unread = json_decode(RedisGet("unread"),TRUE);
		if (empty($unread[$uuid]['1'])) {
			$unread[$uuid]['1'] = 0;
		}
		if (empty($unread[$uuid]['2'])) {
			$unread[$uuid]['2'] = 0;
		}
		$unread[$uuid]['2'] += 1;
		RedisSet('unread',json_encode($unread));
		$uuid_array = json_decode(RedisGet("uuid".$uuid),TRUE);
		$redisarr['oid'] = $orderdata['id'];
		$redisarr['shot_time'] = 1;
		$redisarr['state'] = 1;
		$redisarr['type'] = $orderdata['type'];
		$uuid_array['order_list'][] = $redisarr;
		// p($uuid_array);exit();
		RedisSet('uuid'.$uuid,json_encode($uuid_array));
		$order_array['list'][$uuid] = 3;
		$order_array['status'] = 0;
		// p($order_array);
		RedisSet('order'.$oid,json_encode($order_array));
// exit();
		$res1 = $db_order->where(array("id"=>$oid))->save($arr);
		$res4 = M('musictime')->where(array("oid"=>$oid))->delete();
		if ($res1) {
			M('signreorderlog')->add(array("oid"=>$oid,"uuid"=>$olduuid,"reuuid"=>$uuid,"mid"=>$orderdata['media_id'],"time"=>$now_time));
			$systemdata = M("systemsetup")->where("id=4")->where(array("type"=>0))->find();
			// $GetSingAccessToken = $this->GetSingAccessToken();
			$GetAccessToken = $this->GetAccessToken();
			$pusharray[] = A("Template")->sendorderMessage($wechatinfo,$orderdata,$systemdata['value'],$GetAccessToken);
			$res = curl_multi($pusharray);
			$this->adminlog("转单:".$oid." 给:".$uuid);
			$this->success('转单成功',$jumpurl,1);
		}else{
			$this->error('操作失败，别乱点了，联系技术人员',"",5);
		}
	}else{
		$this->error('主播不存在或未认证',"",1);
	}

}


//派发订单列表
public function sendorder_list()
{
		// p($_POST);exit();
		$db_order = M("order");
		$ordertype = I('get.ordertype');
		$soundtype = I('get.soundtype');
		$status = I('get.status');
		$order_name = I('get.order_name');
		$statustype = I('get.statustype')?I('get.statustype'):0;
		$rejecttype = I('get.rejecttype')?I('get.rejecttype'):0;
		$sex = I('get.sex')?I('get.sex'):0;
		$mid = I('get.mid')?I('get.mid'):0;
		$this->status = $status;
		$this->ordertype = $ordertype;
		$this->soundtype = $soundtype;
		$this->order_name = $order_name;
		$this->statustype = $statustype;
		$this->rejecttype = $rejecttype;
		$this->sex = $sex;
        switch ($status){
            case 0:$where = "(type=3 or type=4)";break;
            case 1:$where = "type=4 and status=1";break;
            case 2:$where = "type=4 and status=3";break;
            case 3:$where = "type=3 and status=1";break;
            case 4:$where = "type=3 and status in (11,12)";break;
            case 5:$where = "type=3 and status=3";break;
            case 6:$where = "type=3 and status in (5,6,7,8)";break;
            case 10:$where = "type=4 and status=3 and ((pay_time+900)<".time().")";break;
        }
        if($sex){$where .= " and sex = $sex";}
		if (!empty($soundtype)) {$where .= " and category = \"".($soundtype)."\" ";}
		if ($statustype == 1) {$where .= " and (audio_upload_time-pay_time)<300 ";}
		if ($rejecttype == 1) {$where .= " and isreject=1 ";}
		if (!empty($order_name)) {$where .= " and (id like '%$order_name%' or title like '%$order_name%' or article_id like '%$order_name%')";}
		if ($ordertype == 1) {$where .= " and isimportant=1 ";}

		// echo $where;exit();
		$count = $db_order->where($where)->count();
		$p = getpage($count, 20);
		$orderlist = $db_order->where($where)->order("isreject=1 desc,status=1 desc,id desc")->limit($p->firstRow, $p->listRows)->select();
		foreach ($orderlist as $key => &$value) {
			if ($value['type'] == 4 && $value['adminid']!=0) {
				$adminname = M("admin")->where(array("heard_admin_id"=>$value['adminid']))->find()['heard_adminname'];
				$value['user_id'] = substr($adminname, -4);
			}elseif($value['status'] == 11 || $value['status'] == 12){
				$value['user_id'] = array_keys(json_decode(RedisGet('order'.$value['id']),TRUE)['list'])['0'];
			}
			$value['passmessage'] = M('rejectorderlog')->where(array("oid"=>$value['id']))->order("time desc")->find()['passmessage'];
		}
		$page = $p->show();
		// 获取查询参数
		$map['order_name'] = empty($order_name)?"":$order_name;
		$map['ordertype'] = $ordertype;
		$map['soundtype'] = $soundtype;
		$map['sex'] = $sex;
		$p->parameter = "";
		foreach($map as $key=>$val) {
				$p->parameter .= "$key=".urlencode($val)."&";
		}
		// p($p);exit();
		$this->assign('orderlist',$orderlist);
		$this->assign('page', $page);
		$this->display();
}
//派单抽审列表
public function sendcallback_list()
{
		// p($_POST);exit();
		$db_order = M("order t");
		$soundtype = I('get.soundtype');
		$order_name = I('get.order_name');
		$this->soundtype = $soundtype;
		$this->order_name = $order_name;
		$where = "(t.type=3 or t.type=4)";
		if (!empty($soundtype)) {$where .= " and category = \"".($soundtype)."\" ";}
		if (!empty($order_name)) {$where .= " and (id like '%$order_name%' or title like '%$order_name%' or article_id like '%$order_name%')";}
		// echo $where;exit();
		$where .= " and t.adminid=0 and (t.status=6 or t.status=8) and (s.type=2 or s.type=3)";
		$count = $db_order
							->join('__SENDORDERSCORE__ s ON t.id = s.oid',LEFT)
							->join('__MEMBER__ m ON t.user_id = m.uuid',LEFT)
							->join('__ADMIN__ a ON s.adminid = a.heard_admin_id',LEFT)
							->field('t.id')
							->where($where)->count();
		$p = getpage($count, 20);
		$orderinfo = $db_order
							->join('__SENDORDERSCORE__ s ON t.id = s.oid',LEFT)
							->join('__MEMBER__ m ON t.user_id = m.uuid',LEFT)
							->join('__ADMIN__ a ON s.adminid = a.heard_admin_id',LEFT)
							->field('t.*,IFNULL(s.type,0) type,m.username,m.nickname,s.message,a.heard_adminname')
							->where($where)->order("id desc")->limit($p->firstRow, $p->listRows)->select();
		/*foreach ($orderinfo as $key => &$value) {
			if (empty($value['type'])) {
				$value['type'] = 0;
			}
		}*/
		$page = $p->show();
		// 获取查询参数
		$map['order_name'] = empty($order_name)?"":$order_name;
		$map['soundtype'] = $soundtype;
		$p->parameter = "";
		foreach($map as $key=>$val) {
			$p->parameter .= "$key=".urlencode($val)."&";
		}
		// p($orderinfo);exit();
		$adminid = urlsafe_b64decode(cookie('heardadminData'));
		$this->adminid = $adminid;
		$this->assign('orderinfo',$orderinfo);
		$this->assign('page', $page);
		$this->display();
}
	//回访派单
	public function callback()
	{
		// p($_GET);exit();
		$oid = I('get.oid');
		$db_sendorderscore = M("sendorderscore");
		if ($oid) {
			$db_sendorderscore->where(array('oid'=>$oid))->save(array('type'=>3));
			$this->adminlog("回访派单:".$oid);
			$this->success('处理成功',"/Home/Signorder/sendcallback_list",1);
		}else{
			$this->error('处理失败',"",1);
		}
	}

//派单数据
public function sendorderdata()
{
	// p($_POST);
	// exit();
		// $strat = I('post.strat')?strtotime(I('post.strat')):strtotime(date("Y-m-d",time()));
		// $end = I('post.end')?strtotime(I('post.end')):time();
	$strat = I('post.strat')?strtotime(I('post.strat')):"";
	$end = I('post.end')?strtotime(I('post.end')):"";
	$db_order = M("order t");
	$data = array();
	$true = "(type=3 or type=4) and LENGTH(0+article_id) != LENGTH(article_id) and ";
	if ($strat&&$end) {
		$where['pay_time'] = array("BETWEEN",array($strat,$end));
		$data['allnum'] = $db_order->where($where)->where($true."(status=6 or status=8)")->count();
		$data['type0'] = $db_order->where($where)->where($true."category=1 and (status=6 or status=8)")->count();
		$data['type1'] = $db_order->where($where)->where($true."category=2 and (status=6 or status=8)")->count();
		$data['type2'] = $db_order->where($where)->where($true."category=3 and (status=6 or status=8)")->count();
		$data['type3'] = $db_order->where($where)->where($true."category=4 and (status=6 or status=8)")->count();
		$data['NoReplyorder'] = $db_order->where($where)->where($true."status in (11,12) and adminid=0")->count();
		// $data['NoReplyuser'] = count($db_order->join('__ORDERINFO__ i ON t.id = i.oid',LEFT)->where($where)->where($true."status=11 and adminid=0")->distinct(true)->field("i.uuid")->select());
		$data['trueorder'] = $db_order->where($where)->where($true."(status=6 or status=8) and adminid=0")->count();
		$data['trueuser'] = count($db_order->where($where)->where($true."(status=6 or status=8) and adminid=0")->distinct(true)->field("user_id")->select());
		$data['timemin'] = $db_order->where($where)->where($true."(status=6 or status=8) and adminid=0")->field("audio_upload_time-pay_time time,words")->order("audio_upload_time-pay_time asc")->find();
		$data['timemax'] = $db_order->where($where)->where($true."(status=6 or status=8) and adminid=0")->field("audio_upload_time-pay_time time,words")->order("audio_upload_time-pay_time desc")->find();
		$data['admintimemin'] = $db_order->where($where)->where($true."(status=6 or status=8) and adminid!=0")->field("audio_upload_time-pay_time time,words")->order("audio_upload_time-pay_time desc")->find();
		$data['todayuser'] = $db_order->where($where)->where($true."(status=6 or status=8) and adminid=0")->field("user_id,count(user_id)")->group("user_id")->select();
	}
	$today = strtotime(date("Y-m-d",time()));
	$now = time();
	$yestoday = strtotime(date("Y-m-d",time()))-86400;
	$where2['pay_time'] = array("BETWEEN",array($today,$now));
	$where3['pay_time'] = array("BETWEEN",array($yestoday,$today));
	$tx['tx_today'] = $db_order->where($where2)->where($true."(status=1 or status=3 or status=6 or status=8)")->count();
	$tx['tx_yestoday'] = $db_order->where($where3)->where($true."(status=1 or status=3 or status=6 or status=8)")->count();
			// echo $db_order->_sql();exit();
		//exit();
	$this->strat = $strat;
	$this->end = $end;
	$this->assign('data',$data);
	$this->assign('tx',$tx);
	$this->display();
}

// 处理腾讯科技订单
public function sendreorder()
{
	// p($_POST);exit();
	$article_id = (string)I('post.article_id');
	$anchor_id = (string)I('post.anchor_id');
	$oid = (string)I('post.oid');
	$mp3url = "http://audio.heardtech.com/".(string)I('post.audio_mp3');
	$sex = I('post.sex');
	$time = (string)time();
	$body['article_id'] = $article_id;
	$body['url'] = $mp3url;
	$body['sex'] = $sex;
	$body['voice_duration'] = (int)(json_decode(do_curl($mp3url.'?avinfo'),true)['streams'][0]['duration']);
	$body['anchor_id'] = $anchor_id;
	$secret = "4c914ce4476b1afc83bf07ac8c762efe";
	$a =  md5($time.$secret.json_encode($body,true));
	$body = json_encode($body,true);

	// $url = 'http://test.dreamreader.qq.com/openapi/v1/shandian/audio?sign='.$a.'&amp;timestamp='.$time;
	$url = 'https://api.dreamreader.qq.com/openapi/v1/shandian/audio?sign='.$a.'&amp;timestamp='.$time;
	// $res = $this->object_array(http_post_json($url,$body));
	$res = json_decode(http_post_json($url,$body),true);
	$this->adminlog($article_id."重传派单:".json_encode($res));
	if($res['errno'] == 0 /*&& $res['data']['res'] == true*/){
		M("order")->where("id=$oid")->save(array("audio_link"=>I('post.audio_mp3')));
		M("order")->where(array("article_id"=>$article_id,"isreject"=>1))->save(array("isreject"=>0));
		$this->success('处理成功',"",1);
	}else{
		$this->error($res['errmsg'],"",1);
	}
}

    // 对象转数组
    public function object_array($array) {
        if(is_object($array)) {
            $array = (array)$array;
        }
        if(is_array($array)) {
            foreach($array as $key=>$value) {
                $array[$key] = $this->object_array($value);
            }
        }
        return $array;
    }

    public function signorder_slip_list(){
		$oid = I('get.oid');
		$slip_list = M('signreorderlog l')
			->field('l.id,l.oid,o.media_name,o.title,o.category,o.level,o.sex,o.words,o.bgm_id,o.pay_time,o.createtime,l.time,l.uuid,l.reuuid,o.status')
			->where(['oid'=>$oid])
			->join('__ORDER__ o on o.id = l.oid')
			->order('l.id DESC')
			->select();
		$end_id = M('signreorderlog')->where(['oid'=>$oid])->order('time DESC')->getField('id');
		foreach ($slip_list as &$v){
			if($v['id'] == $end_id){
				switch($v['status']){
					case 0:$v['status_name'] = '订单作废';break;
					case 1:$v['status_name'] = '未接单';break;
					case 3:$v['status_name'] = '已接单';break;
					case 5:$v['status_name'] = '已交付未传wav';break;
					case 6:$v['status_name'] = '已交付未结算';break;
					case 7:$v['status_name'] = '已评价未传wav';break;
					case 8:$v['status_name'] = '已交付已结算';break;
					case 9:$v['status_name'] = '需要重新上传音频';break;
					case 11:$v['status_name'] = '无人接单';break;
					case 12:$v['status_name'] = '无人接单';break;
					case 13:$v['status_name'] = '超时未能完成';break;
					case 15:$v['status_name'] = '用户主动取消订单';break;
				}
			}else{
				$v['status_name'] = '已转单';
			}
		}
		$this->assign('slip_list',$slip_list);
		$this->display();
	}
/*-----------------------*/
}